Skip to main content

Custom Physical Properties

You can easily set universal physical properties which will be adhered by every RigidBody and Constraint!

In order to set universal physical properties, use the Engine:SetPhysicalProperty() method!

This method takes in 2 parameters - The property name, which is a string and its new value. Here are the physical properties you can set as of now:

  • Gravity - Vector2 (By default Vector2.new(0, 0.3))
  • Friction - number (By default 0.01)
  • AirFriction - number (By default 0.01)
  • CollisionMultiplier - number (By default 0.8)
  • UniversalMass - number (By default 1)

Gravity is a vector, the force is applied every RenderStepped on all rigid bodies. You can simulate 0 gravity or even sideways gravitational force! An example from the previous tutorial:

ScreenGui/Example.client.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Nature2D = require(ReplicatedStorage:FindFirstChild("Nature2D"))

local ScreenGui = script.Parent
local Canvas = ScreenGui.Canvas

local engine = Nature2D.init(ScreenGui)

for _, box in ipairs(Canvas.Boxes:GetChildren()) do
engine:Create("RigidBody", { Object = box, Collidable = true, Anchored = false })
end
engine:SetPhysicalProperty("Gravity", Vector2.new(.2, 0)) -- sideways
engine:Start()

Custom friction and airfriction damping value can also be set to increase or decrease friction. The higher the value of friction, the higher it is and vice-versa!

engine:SetPhysicalProperty("Friction", 0.01)
engine:SetPhysicalProperty("AirFriction", 0.01)

CollisionMultiplier is a multiplier value used to increase or decrease the repulsion force when a RigidBody collides with the boundaries of the canvas.

engine:SetPhysicalProperty("CollisionMultiplier", 0.1)

UniversalMass is the default mass value for any RigidBody in the Engine. This value will be used if Mass isn't specified for a RigidBody on creation.

engine:SetPhysicalProperty("UniversalMass", 5)